#include"iostream"

using namespace std;

const int N = 100010;

int stack[N], n, x, tail;

int main()
{
	scanf("%d",&n);
	while(n--){
		cin >> x;
		while(tail && stack[tail] >=x) tail--;
		if(tail) cout << stack[tail] << ' ';
		else cout << -1 << ' ';
		stack[++tail] = x;
	}
}